package com.ftg.learn.day11;

import com.ftg.learn.day09.exam02.Dog;
import com.ftg.learn.day10.factory.homework.Fly;
import com.ftg.learn.day10.factory.homework.Lion;

import java.io.*;
import java.util.Arrays;

/**
 * 学习一下字符流 : 文本
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/8/18 上午10:09
 */
public class CharStream {

    public static void main(String[] args) {
        //字符读流
        //FileReader读文件
        try (
                Reader reader = new FileReader("/home/kangjx/Desktop/实现化的类的名称.txt");
        ) {
            StringBuilder stringBuilder = new StringBuilder();
            while (reader.ready()) {
                stringBuilder.append((char) reader.read());
            }
            String[] classes = stringBuilder.toString().split("，");
            Object[] obj = new Object[classes.length];
            int index = 0;
            for (int i = 0; i < classes.length; i++) {
                switch (classes[i]){
                    case "狗":
                        obj[index++] = new Dog();
                        break;
                    case "猫":
                        obj[index++] =new Fly();
                        break;
                    case "狮子":
                        obj[index++] =new Lion();
                        break;
                }
            }


            System.out.println(Arrays.toString(obj));

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


}
